//
//  CLSearchViewController.m
//  chanlin
//
//  Created by shuhui on 15-5-10.
//  Copyright (c) 2015年 chanlin. All rights reserved.
//

#import "CLSearchViewController.h"
#import "CLSearchDataModel.h"
#import "CLSearchCollectionViewFlowLayout.h"
#import "CLSearchResultCell.h"

#import "CLSlidersViewController.h"
#import "CLDocViewController.h"
#import "CLTopicViewController.h"
#import "CLVideoViewController.h"
#import "CLSubViewController.h"
#import "ReadDocHistory.h"
#import "EColumn.h"
#import "SearchNewsEntity.h"
#import "IFIndexCell.h"
#import "CLPushAnimatedRight.h"
#import "IFCoreDataManager.h"
#import "CLIndexModel.h"

#import "IFIndexFocusCell.h"
#import "IFIndexIconCell.h"
#import "IFIndexSlidesCell.h"

#import "CLLiveViewController.h"
#import "IFIndexClassCell.h"
#import "IFIndexAudioCell.h"
#import "CLWebVeiwController.h"

#define _CELL @"acell"

@interface CLSearchViewController ()
@property (nonatomic,strong) UIView *topView;
@property (nonatomic, strong) UISearchBar *newsSearchBar;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) CLSearchDataModel *model;
@property (nonatomic,strong) UIView *backGroundView;
@property (nonatomic,strong) UIImageView *errorImgView;
@property (nonatomic,unsafe_unretained) NSInteger pagenum;
@property (nonatomic,strong)NSString *searchWord;

@property (nonatomic,strong)UILabel *topSearchLabel;



@end

@implementation CLSearchViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.pagenum=1;
    
    self.view.backgroundColor = RGB(0xf8, 0xf8, 0xf8);
     _model = [[CLSearchDataModel alloc] init];
    __weak typeof(self) me=self;
    
    [_model getHotKeyWordsWithUICallBack:^(BOOL success, id responseObj, NSError *message, NSMutableDictionary *param) {
        if(success){
            [me.collectionView reloadData];
            [me initCollectionView];
        }
    }];
    
    [self initWithbackGroundView];
    
    [self createTopView];
    
    UIImageView *stateBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    stateBarView.backgroundColor = RGB(0xff, 0xff, 0xff);
    [self.view addSubview:stateBarView];
    
    [self createResultTableView];
    
    
    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"sort" ascending:YES];
    NSFetchRequest *req = [[NSFetchRequest alloc] initWithEntityName:@"CLList"];
    req.predicate = [NSPredicate predicateWithFormat:@"category=%@", @"search"];
    req.sortDescriptors = @[sort];
    self.fetch = [[NSFetchedResultsController alloc] initWithFetchRequest:req
                                                     managedObjectContext:[IFCoreDataManager sharedInstance].mainMoc
                                                       sectionNameKeyPath:nil
                                                                cacheName:nil];
    self.fetch.delegate=self;
    [self.fetch performFetch:nil];
    
    self.tableView.refrashType = JTableViewRefrashType_RefrashAuto;
    //[self doReflashWithAnimation:self.isCurrent];
    
    
    if([self isViewLoaded])
        [self reloadTable];

    
}

//搜索结果
-(void)createResultTableView{
    
    self.tableView.frame=CGRectMake(0, _newsSearchBar.bottom+20.f, GlobleWidth, GlobleHeight-_newsSearchBar.bottom-20.f);
    [self.tableView hiddenHead];
    [self.view bringSubviewToFront:self.tableView];
    
//    _resultsTableView=[[JTableView alloc] initWithFrame:CGRectMake(0, _newsSearchBar.bottom, GlobleWidth, GlobleHeight-_newsSearchBar.bottom)];
//    _resultsTableView.scrollsToTop=NO;
//    _resultsTableView.delegate=self;
//    _resultsTableView.dataSource=self;
//    _resultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
////    [_resultsTableView removeRefrashHeadView];
//    [self.view addSubview:_resultsTableView];
//    _resultsTableView.hidden = YES;
    self.tableView.hidden=YES;
}

- (void) createTopView {
    _topView = [[UIView alloc] initWithFrame:CGRectMake(0, AtLeastIOS8?20:0, GlobleWidth,45-1)];
    _topView.backgroundColor = RGB(0xff, 0xff, 0xff);
    [self.view addSubview:_topView];
    [self createSearchItems];
    [self createCancelBtn];
    UIView *seperatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, _topView.frame.size.height-0.5, GlobleWidth, 0.5)];
    seperatorLine.backgroundColor = RGB(0xe0, 0xe0, 0xe0);
    [_topView addSubview:seperatorLine];
    
}

/**
 *  create SearchBar & resultsDataTable
 */
- (void)createSearchItems
{
    _newsSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(5,0, GlobleWidth-50, 45-1)];
    
    _newsSearchBar.backgroundColor = RGB(0xff, 0xff, 0xff);
    [_newsSearchBar setPositionAdjustment:UIOffsetMake(0, 0) forSearchBarIcon:UISearchBarIconSearch];
    
    NSArray *subviewContainer = ((UIView *)_newsSearchBar.subviews[0]).subviews;
    for (UIView *sub in subviewContainer) {
        if ([sub isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            sub.alpha = 0.f;
        }
        
        if ([sub isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
            sub.layer.borderWidth = 0.5;
            
            sub.backgroundColor = [UIColor clearColor];
            sub.layer.borderColor = RGB(0xe0, 0xe0, 0xe0).CGColor;//[UIColor clearColor].CGColor;
            
                
                if([sub isKindOfClass:[UITextField class]]){
                    ((UITextField *)sub).textColor = RGB(0xc9, 0xc9, 0xc9);
                    ((UITextField *)sub).textAlignment = NSTextAlignmentLeft;
                   
                }
        }
    }
    
    _newsSearchBar.delegate = self;
    _newsSearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    _newsSearchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    _newsSearchBar.keyboardType = UIKeyboardTypeDefault;
    [_newsSearchBar setShowsScopeBar:NO];
    _newsSearchBar.showsCancelButton = NO;
    [_topView addSubview:_newsSearchBar];
    
    [_newsSearchBar becomeFirstResponder];
    _newsSearchBar.placeholder = [NSString stringWithCString:"  输入关键字" encoding: NSUTF8StringEncoding];
    
}

-(void)createCancelBtn{
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(_newsSearchBar.frame.origin.x+_newsSearchBar.frame.size.width-5, _newsSearchBar.frame.origin.y, 50,44);
    cancelBtn.backgroundColor = [UIColor clearColor];
    UILabel *cancelLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cancelBtn.frame.size.width, cancelBtn.frame.size.height)];
    cancelLab.text = @"取消";
    cancelLab.textAlignment = NSTextAlignmentCenter;
    cancelLab.font = [UIFont systemFontOfSize:15];

    cancelLab.textColor = RGB(0x87, 0x89, 0x88);
    
    cancelLab.backgroundColor = [UIColor clearColor];
    [cancelBtn addSubview:cancelLab];
    [cancelBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    [_topView addSubview:cancelBtn];
}

-(void)goBack{
    [_newsSearchBar resignFirstResponder];
    [self.dispatchObj pop];
}

- (void)initWithbackGroundView
{
    _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, _newsSearchBar.frame.origin.y+_newsSearchBar.frame.size.height, GlobleWidth, GlobleHeight-(_newsSearchBar.frame.origin.y+_newsSearchBar.frame.size.height))];
    _backGroundView.backgroundColor = RGB(0xf8, 0xf8, 0xf8);
    
    [self.view addSubview:_backGroundView];
    _backGroundView.hidden = YES;
    
    _errorImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 57, 150)];
    _errorImgView.center = CGPointMake(_backGroundView.center.x,_backGroundView.center.y-40);
    [_errorImgView  setImage:[UIImage imageNamed:@"list_search_no_data.png"]];
    _errorImgView.hidden = YES;
    [_backGroundView addSubview:_errorImgView];
    
    /*
    _errorButton = [[IfengStateButton alloc] initWithFrame:CGRectMake(0, 0, SearErrorBtnW, SearErrorBtnH)];
    _errorButton.center = CGPointMake(_backGroundView.center.x,_backGroundView.center.y-SearErrorBtnCY);
    _errorButton.backgroundColor = [UIColor clearColor];
    [_errorButton setButtonstateSearching];
    [_backGroundView addSubview:_errorButton];*/
}

- (void)initCollectionView {
    
    UILabel *topSearchLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, _topView.frame.size.height+_topView.frame.origin.y+12, 100, 13)];
    topSearchLabel.backgroundColor = [UIColor clearColor];
    [topSearchLabel setText:@"热门搜索："];
    topSearchLabel.font = [UIFont systemFontOfSize:14];
    topSearchLabel.textColor = RGB(0x56, 0x56, 0x4d);
    
    [self.view addSubview:topSearchLabel];
    
    self.topSearchLabel=topSearchLabel;
    
    
    CLSearchCollectionViewFlowLayout *layout = [[CLSearchCollectionViewFlowLayout alloc]init];
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(11, topSearchLabel.frame.origin.y+topSearchLabel.frame.size.height+12, GlobleWidth-2*11, GlobleHeight-82-20) collectionViewLayout:layout];
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:_CELL];
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView setAutoresizingMask:UIViewAutoresizingNone];
   // [self.view addSubview:_collectionView ];
    [self.view insertSubview:_collectionView belowSubview:self.tableView];
    [_collectionView reloadData];
    
}

#pragma mark -
#pragma mark - collectionView
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.model.dataArray.count;
}

//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:_CELL forIndexPath:indexPath];
    for (UIView*view in cell.contentView.subviews) {
        if (view) {
            [view removeFromSuperview];
        }
    }
    cell.userInteractionEnabled = YES;
    
    UIView* BGView = [[UIView alloc] initWithFrame:cell.bounds];
    BGView.backgroundColor = RGB(0xf8, 0xf8, 0xf8);
    cell.backgroundView = BGView;
    
    cell.backgroundColor = RGB(0xff, 0xff, 0xff);
    
    UILabel* titleLabel = [[UILabel alloc]initWithFrame:cell.bounds];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.layer.borderColor = RGB(0xe0, 0xe0, 0xe0).CGColor;
    titleLabel.layer.borderWidth = 0.5;
    titleLabel.layer.cornerRadius = 2;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = RGB(0x56, 0x56, 0x5e);
    [titleLabel setText:[self.model.dataArray objectAtIndex:indexPath.row]];
    [titleLabel setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:titleLabel];
    
    return cell;
}

#pragma -
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *str = [self.model.dataArray objectAtIndex:indexPath.row];
    //sizeWithAttributes
    int lenght = [str sizeWithFont:[UIFont systemFontOfSize:13]].width;
    CGFloat width = lenght+20;
    return CGSizeMake(width, 32);
}

#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    _newsSearchBar.text = [self.model.dataArray objectAtIndex:indexPath.row];
    [self searchBarSearchButtonClicked:_newsSearchBar];

}

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.contentView.backgroundColor = RGB(0xff, 0xff, 0xff);
}

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.contentView.backgroundColor = RGB(0xff, 0xff, 0xff);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -
#pragma mark UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    self.tableView.hidden = (!(self.fetch.fetchedObjects.count>0) || _isStrNULL(searchBar.text));
    _backGroundView.hidden = _isStrNULL(searchBar.text)?YES:_backGroundView.hidden;
    self.topSearchLabel.hidden=!self.tableView.hidden;
    return YES;
}

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    return YES;
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
    self.tableView.hidden = _isStrNULL(searchText)?YES:_resultsTableView.hidden;
    _backGroundView.hidden = _isStrNULL(searchText)?YES:_backGroundView.hidden;
    self.topSearchLabel.hidden=!self.tableView.hidden;
    if(_isStrNULL(searchText)){
        [[CLIndexModel sharedInstance] deleteSearch];
    }
    
}

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
    [searchBar resignFirstResponder];
    
}

#pragma mark -
#pragma mark UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"  "];
    NSString *searchText = [searchBar.text mutableCopy];
    searchText = [[searchText componentsSeparatedByCharactersInSet: doNotWant]componentsJoinedByString: @""];
    if(_isStrNULL(searchText)){
        [[CLGloble sharedInstance] showTieAlertMessage:@"空字符" subMessage:@"内容不能为空"];
        return;
    }
    [searchBar resignFirstResponder];
    
//    [self showLoadingState:YES];
//    _model.pageNum = 1;
    self.searchWord=searchText;
    typeof(self) __weak me = self;
    self.pagenum=1;
    [[CLIndexModel sharedInstance] getSearchListWithKeyWord:searchText
                                                    pageNum:self.pagenum
                                                    lsatObj:self.fetch.fetchedObjects.lastObject
                                                    uiBlock:^(BOOL success, id responseObj, NSString *message) {
                                                       
                                                        
                                                        me.tableView.hidden=!(me.fetch.fetchedObjects.count>0);
                                                        me.topSearchLabel.hidden=!me.tableView.hidden;
                                                        [me.view bringSubviewToFront:me.tableView];
                                                        if(success)me.pagenum++;
    }];
    
    

}

- (void)jTableViewStartBottomMoreLoading:(JTableView *)tableView{
    __weak typeof(self) me=self;
    
  
    [[CLIndexModel sharedInstance] getSearchListWithKeyWord:me.searchWord
                                                    pageNum:self.pagenum
                                                    lsatObj:self.fetch.fetchedObjects.lastObject
                                                    uiBlock:^(BOOL success, id responseObj, NSString *message) {
                                                        me.tableView.hidden=NO;
                                                        [me.view bringSubviewToFront:me.tableView];
                                                        if(success){me.pagenum++;
                                                        [me.tableView stopBottomMoreWithScuessLoading];
                                                        
                                                        }else{
                                                        [me.tableView stopBottomMoreWithNothingLoading];
                                                        }
                                                    }];

    
  
}

#pragma mark -
#pragma mark  -TableViewDataSource--

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, GlobleWidth, 34.f)];
    header.backgroundColor = RGB(0xec, 0xec, 0xec);
    
    
    UILabel *textLab = [[UILabel alloc] initWithFrame:CGRectMake(11.f, 11.f, 100.f, 13.f)];
    textLab.font = [UIFont systemFontOfSize:13.f];
    textLab.textColor = RGB(0x58, 0x58, 0x58);
    
    [header addSubview:textLab];
    textLab.text = @"禅林";
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (0==section && [self.fetch.fetchedObjects count]<1) return 0;
    return 34.f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CLList *newsList=[self.fetch objectAtIndexPath:indexPath];
    return newsList.cHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CLList *list=[self.fetch objectAtIndexPath:indexPath];
    IFIndexCell *cell=[self cellForStyle:list.style tableView:tableView indexpath:indexPath];
    [cell loadData:list];
    [cell setPlayVideo:list.link==CLList_video];
    if(list.link!=CLList_sub)
        [cell setIsRead:[[ReadDocHistory shareInstance] check:list.itemId]];
    
    
    
    cell.indexPath=indexPath;
    cell.delegate=self;
    if(_isStrNotNull(self.searchWord)){
    NSRange range=[list.title rangeOfString:self.searchWord];
    [cell setRedRange:range];
    }
    
    return cell;
}



- (IFIndexCell *)cellForStyle:(int)style tableView:(UITableView *)tableView indexpath:(NSIndexPath *)indexPath{
    IFIndexCell *rcell=nil;
    
    if(style==CLList_style_focus){
        NSString *cellID=[NSString stringWithFormat:@"IFIndexFocusCell%@%@",@(indexPath.section),@(indexPath.row)];
        // static NSString *cellID=str;
        IFIndexFocusCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexFocusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            __weak typeof(self) me=self;
            cell._blkTapResponse=^(CLList *indexList,int index,NSIndexPath *indexPath){
                CLList *list=[indexList.focus sgrGetType:[CLList class] forIndex:index];
                [me clickOnList:list];
            };
        }
        rcell= cell;
    }else if (style==CLList_style_doc_img){
        static NSString *cellID=@"IFIndexIconCell";
        IFIndexIconCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        rcell= cell;
    }else if(style==CLList_style_doc){
        static NSString *cellID=@"IFIndexTitleCell";
        IFIndexTitleCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexTitleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        rcell= cell;
    }else if(style==CLList_style_slide){
        static NSString *cellID=@"IFIndexSlidesCell";
        IFIndexSlidesCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexSlidesCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        rcell= cell;
    }else if(style==CLList_style_topic_sub){
        static NSString *cellID=@"IFIndexClassCell";
        IFIndexClassCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexClassCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        rcell= cell;
    }else if(style==CLList_style_audio){
        static NSString *cellID=@"IFIndexAudioCell";
        IFIndexAudioCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if(!cell){
            cell=[[IFIndexAudioCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        rcell= cell;
        
    }
    if(!rcell){
        rcell = [[IFIndexCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IFIndexCell"];
    }
    
//    rcell.keyword=self.searchWord;
    
    
    return rcell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CLList *list=[self.fetch objectAtIndexPath:indexPath];
    [self clickOnList:list];
    IFIndexCell *cell=(IFIndexCell *)[tableView cellForRowAtIndexPath:indexPath];
    if(list.link!=CLList_sub)
        [cell setIsRead:YES];
}

- (void)didSelect:(NSIndexPath *)indexPath{
    CLList *list=[self.fetch objectAtIndexPath:indexPath];
    [self clickOnList:list];
    IFIndexCell *cell=(IFIndexCell *)[self.tableView cellForRowAtIndexPath:indexPath];
    if(list.link!=CLList_sub)
        [cell setIsRead:YES];
}

- (void)clickOnList:(CLList *)list{
    if(list.link==CLList_sliders){
        CLSlidersViewController *slider=[CLSlidersViewController new];
        slider.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:slider];
        
    }else if(list.link==CLList_doc){
        CLDocViewController *doc=[CLDocViewController new];
        doc.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:doc];
    }else if(list.link==CLList_topic){
        CLTopicViewController *topic=[CLTopicViewController new];
        topic.title=list.title;
        topic.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:topic];
    }else if(list.link==CLList_video){
        CLVideoViewController *video=[CLVideoViewController new];
        video.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:video];
    }else if(list.link==CLList_sub){
        CLSubViewController *sub=[CLSubViewController new];
        sub.itemId=list.classId;
        sub.objectiveId=list.objectID;
       // sub.channel=self.categroyDic;
        //[sub loadData:list];
        [[CLPushAnimatedRight sharedInstance] pushController:sub];
    }else if(list.link==CLList_audio){
        CLDocViewController *doc=[CLDocViewController new];
        doc.isAudio=YES;
        doc.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:doc];
    }else if(list.link==CLList_live){
        CLLiveViewController *live=[CLLiveViewController new];
        
        live.itemId=list.itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:live];
        return;
        
        
    }else if(list.link==CLList_web){
        CLWebVeiwController *web = [CLWebVeiwController new];
        
        web.itemId=list.url;
        [[CLPushAnimatedRight sharedInstance] pushController:web];
        return;
        
    }else{
        [[CLGloble sharedInstance] showAlertWithTitle:@"提示"
                                              message:@"请升级新版本app，支持此功能"
                                                block:nil
                                    cancelButtonTitle:@"确定" button1:nil button2:nil];
    }
    
}


@end
